﻿///***************************************************************
/// 시  스  템 : Updms.Cfg
/// 단위시스템 : CFG
/// 계      층 : Presentation Layer
/// 프로그램명 : Cfg3012p
/// 파  일  명 : Cfg3012p.aspx.cs
/// 설      명 : 설정값 조회팝업
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2014-05-16 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;

using SMFramework.Utility;

using Base.Dac;
using Updms.Com.Exe;
using Updms.Crd.Exe;
using Updms.Prj.Exe;
using Updms.Ref.Exe;

namespace Updms.Cfg
{
	public partial class Cfg3012p : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		//프로그램상수
		public static readonly string PID = "Cfg3012p";
		public static readonly string gs_path_info = "/updms/Cfg/" + PID + ".aspx";

		Global global = new Global();
		CommCode.Com com = new CommCode.Com(LANG_SET);
		CommCode.Cfg cfg = new CommCode.Cfg(LANG_SET);
		AccessCheck access = new AccessCheck();

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			SetInit();
			if (!Page.IsPostBack)
			{
				// 최초 화면 로딩시 처리해야 할 부분
				OnPageLoad();
			}
		}

		// OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
			SetSettingValueDiv();
			SetUseYn();
			SetCardList();
			SetProjectList();
			SetShopList();
			SetSettingValueCtrlVisible("AD001");
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion

		#region SetInit, SetSearchParameter

		//초기값설정
		private void SetInit()
		{
			
		}

		#endregion

		#region 마스터 Method (SetSettingValueDiv)

		//설정값구분
		private void SetSettingValueDiv()
		{
			cfg.SetSettingValueDiv(ddl_search_div);
		}

		#endregion

		#region 디테일 Method (SetUseYn, SetCardList, SetProjectList, SetShopList)

		//사용여부
		private void SetUseYn()
		{
			com.SetUseYn(rbl_use_yn);
		}

		//카드목록
		private void SetCardList()
		{
			DataSet lo_ds = new DataSet();
			Crd1010m_NT _Crd1010m_NT = new Crd1010m_NT();

			lo_ds.Merge(_Crd1010m_NT.GetCardInfoList("Y"));

			ddl_card_cd.Items.Clear();
			ddl_card_cd.DataSource = lo_ds;
			ddl_card_cd.DataMember = "UPDMS_CRD_INFO";
			ddl_card_cd.DataTextField = "Card_Nm";
			ddl_card_cd.DataValueField = "Card_Cd";
			ddl_card_cd.DataBind();
		}

		//프로젝트목록
		private void SetProjectList()
		{
			DataSet lo_ds = new DataSet();
			Prj1010m_NT _Prj1010m_NT = new Prj1010m_NT();

			lo_ds.Merge(_Prj1010m_NT.GetProjectInfo());

			ddl_prj_id.Items.Clear();
			ddl_prj_id.DataSource = lo_ds;
			ddl_prj_id.DataMember = "UPDMS_PRJ_SUMMARY";
			ddl_prj_id.DataTextField = "Subject";
			ddl_prj_id.DataValueField = "Prj_Id";
			ddl_prj_id.DataBind();
		}

		//업소목록
		private void SetShopList()
		{
			DataSet lo_ds = new DataSet();
			Ref1010m_NT _Ref1010m_NT = new Ref1010m_NT();

			lo_ds.Merge(_Ref1010m_NT.GetShopInfoList());

			ddl_shop_id.Items.Clear();
			ddl_shop_id.DataSource = lo_ds;
			ddl_shop_id.DataMember = "UPDMS_REF_SHOP";
			ddl_shop_id.DataTextField = "Shop_Nm";
			ddl_shop_id.DataValueField = "Shop_Id";
			ddl_shop_id.DataBind();
		}

		#endregion

		#region 디테일 이벤트 Method

		//설정값구분 변경시
		protected void ddl_search_div_SelectedIndexChanged(object sender, EventArgs e)
		{
			txt_setting_value.Text = "";
			SetSettingValueCtrlVisible(ddl_search_div.SelectedValue);
		}

		/*
		 *	설정값구분별 콘트롤 활성화 처리
		 *	공통코드(CFG, AD)의 순서와 ls_controls의 순서와 갯수가 일치해야함.
		 *	AD001 직접입력
		 *	AD002 사용여부
		 *	AD003 점수(0.0 ~ 9.9)
		 *	AD004 숫자(1 ~ 100)
		 *	AD005 숫자(10 ~ 100)
		 *	AD006 카드목록
		 *	AD007 프로젝트목록
		 *	AD008 업소목록
		 *	AD009 날짜
		 */
		private void SetSettingValueCtrlVisible(string setting_value_div)
		{
			string ls_controls = "txt_direct_input,rbl_use_yn,txt_score_slider,txt_digit_1_slider,txt_digit_2_slider,ddl_card_cd,ddl_prj_id,ddl_shop_id,txt_dt";
			string[] la_controls = ls_controls.Split(',');

			//AD001 -> 1 -> 0
			int idx = ConversionUtil.ExtractNumberInt(setting_value_div) - 1;

			for (int i = 0; i < la_controls.Length; i++)
			{
				Control c = Page.FindControl(la_controls[i]);
				c.Visible = (i == idx);

				//DropDownList나 RadioButtonList이면 첫번째
				if (c.Visible)
				{
					if (c is DropDownList)
					{
						DropDownList ddl = (DropDownList)c;
						txt_setting_value.Text = ddl.SelectedValue;
					}
					else if (c is RadioButtonList)
					{
						RadioButtonList rbl = (RadioButtonList)c;
						txt_setting_value.Text = rbl.SelectedValue;
					}
					else if (c.ClientID == "txt_dt") //날짜
					{
						ce_dt.SelectedDate = DateTime.Now.AddDays(0);
						txt_setting_value.Text = ce_dt.SelectedDate.Value.ToString("yyyy-MM-dd");
					}
				}
			}
		}

		//사용여부
		protected void rbl_use_yn_SelectedIndexChanged(object sender, EventArgs e)
		{
			SetSettingValue(rbl_use_yn.SelectedItem.Value);
		}

		//카드목록
		protected void ddl_card_cd_SelectedIndexChanged(object sender, EventArgs e)
		{
			SetSettingValue(ddl_card_cd.SelectedValue);
		}

		//프로젝트목록
		protected void ddl_prj_id_SelectedIndexChanged(object sender, EventArgs e)
		{
			SetSettingValue(ddl_prj_id.SelectedValue);
		}

		//업소목록
		protected void ddl_shop_id_SelectedIndexChanged(object sender, EventArgs e)
		{
			SetSettingValue(ddl_shop_id.SelectedValue);
		}

		//설정값 설정
		private void SetSettingValue(string setting_value)
		{
			txt_setting_value.Text = setting_value;
		}

		#endregion

		#region Page_PreRender, ChangePageMode

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				//접근권한 체크
				if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
				{
					Response.Redirect(URL_NO_AUTHORITY_REDIRECT_POPUP);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
				}
			}
		}

		#endregion

		#region 버튼이벤트

		//닫기
		protected void ibtn_close_Click(object sender, EventArgs e)
		{
			string ls_msg = "opener.document.form1['txt_setting_value'].value ='" + txt_setting_value.Text + "';window.close();";

			ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), null, ls_msg, true);
		}


		#endregion

	}
}
